<?php
namespace App\Http\Middleware;


/**
 * 渠道接口校验
 */


use Closure;
use App\Exceptions\BasicException;

class ChannelCheckMiddleware
{
    public function handle($request, Closure $next)
    {
        $timestamp = $request->input('timestamp');
        $sign = $request->input('sign');
        $secret = env("CHANNEL_SECRET");
        $after = time()-$timestamp; //超过15秒也拒绝请求
        if (empty($timestamp) || empty($sign) || $after > 86400  || ($sign != md5($timestamp.$secret))) {
            return response()->json([
                'code' => -1,
                'message'   => '令牌不合法！',
                'data'   => '',
            ]);
        }
        return $next($request);
    }
}
